package com.example.ByteStream;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author Jason
 * @PACKAGE_NAME com.example.ByteStream
 * @Description 文件字节输入流FileInputStream的使用
 * @date 2023-12-11 15:26
 */
public class FileInputStreamDemo {
    public static void main(String[] args) throws IOException {
        //1.创建FileInputStream并指定文件路径
        FileInputStream fis = new FileInputStream("d:\\aa.txt");
        //2.读取文件
        /*//2.1读取单个字节读取
        int data = 0;
        while ((data = fis.read()) != -1) {
            System.out.print((char) data);
        }*/
        //2.2读取多个字节
        byte[] buf = new byte[1024];
        int count = 0;
        while ((count = fis.read(buf)) != -1) {
            System.out.print(new String(buf, 0, count));
        }

        //3.关闭
        fis.close();
        System.out.println("文件读取完毕");
    }
}
